//
//  HotRecomment.m
//  jingdongfang
//
//  Created by MTiMac02 on 2018/5/8.
//  Copyright © 2018年 BOE-SBG-CTO. All rights reserved.
//

#import "HotRecomment.h"
#import "MyFocusMemberModel.h"
@interface HotRecomment()
{
  void(^blocks)(MyFocusMemberModel *info);
}
@property (strong, nonatomic) IBOutlet UIImageView *image;
@property (strong, nonatomic) IBOutlet UILabel *name;
@property (strong, nonatomic) IBOutlet UILabel *worksNum;
@property (strong, nonatomic) IBOutlet UILabel *fansNum;
@property (strong, nonatomic) IBOutlet UIButton *attentBtn;
@end
@implementation HotRecomment
- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.image.contentMode = UIViewContentModeScaleAspectFill;
    self.image.layer.borderWidth = 1;
    self.image.layer.borderColor = [UIColor whiteColor].CGColor;
    self.image.layer.cornerRadius=self.image.width/2;
    self.image.layer.masksToBounds=YES;
 
    self.attentBtn.clipsToBounds=YES;
    self.attentBtn.layer.borderWidth=1.0f;
    self.attentBtn.layer.cornerRadius=15.f;
    self.attentBtn.layer.borderColor=[UIColor c1Color].CGColor;
    self.attentBtn.contentEdgeInsets=UIEdgeInsetsMake(5, 10, 5, 10);
    self.attentBtn.titleLabel.font=[UIFont font14];
    [self.attentBtn setTitleColor:[UIColor c5Color] forState:UIControlStateSelected];
    [self.attentBtn setTitleColor:[UIColor c1Color] forState:UIControlStateNormal];
    [self.attentBtn setTitle:@"已关注" forState:UIControlStateSelected];
    [self.attentBtn setTitle:@"+ 关注" forState:UIControlStateNormal];
    [self.attentBtn addTarget:self action:@selector(attentBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.attentBtn setSelected:NO];
}
-(void)layoutSubviews{
    MyFocusMemberModel *recInfo=self.data;
    [self.image sd_setImageWithURL:[NSURL URLWithString:recInfo.image]];
    self.name.text=recInfo.nike;
    self.worksNum.text=recInfo.worksNum;
    self.fansNum.text=recInfo.followNums;
    if ([recInfo.attentionState integerValue]==0) { //是否 关注  0=已关注，1=未关注
        self.attentBtn.layer.borderColor = [UIColor c5Color].CGColor;
        self.attentBtn.selected=YES;
    } else {
        self.attentBtn.layer.borderColor = [UIColor c1Color].CGColor;
        self.attentBtn.selected=NO;
    }
}

-(void)attentBtnClick:(UIButton *)attBtn{
    self.attentBtn.selected=!self.attentBtn.isSelected;
    if ([self.attentBtn isSelected]) {
        self.attentBtn.layer.borderColor=[UIColor c5Color].CGColor;
    }else{
        self.attentBtn.layer.borderColor=[UIColor c1Color].CGColor;
    }
    if (blocks)
    {
        blocks((MyFocusMemberModel *)self.data);
    }
}
-(void)followOwerAction:(void (^)(MyFocusMemberModel *))block{
     blocks = [block copy];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}
@end
